package nature.nano.component;

import java.util.LinkedHashMap;
import java.util.Map;

import nature.nano.iface.Props;
import nature.nano.iface.enumer.EnumStringPairCallback;

public class SimpleProps implements Props {

	private Map<String, String> props = new LinkedHashMap<String, String>();

	public SimpleProps(String... pairs) {
		int count = pairs.length / 2;
		for (int i = 0; i < count; ++i) {
			add(pairs[i * 2], pairs[i * 2 + 1]);
		}
	}
	
	public SimpleProps(Props source) {
		add(source);
	}

	public void add(String key, String value) {
		props.put(key, value);
	}
	
	public void add(Props source) {
		source.enumProp(
				new EnumStringPairCallback() {
					public void onRead(String key, String value) {
						add(key, value);
					}
				});
	}
	
	public void clear() {
		props.clear();
	}
	
	@Override
	public int enumProp(EnumStringPairCallback callback) {
		for (String key : props.keySet()) {
			callback.onRead(key, props.get(key));
		}
		return props.size();
	}

	@Override
	public String get(String key) {
		return props.get(key);
	}

	@Override
	public int propCount() {
		return props.size();
	}

}
